//
//  MYCExcelCell.m
//  
//
//  Created by 马雨辰 on 2018/10/19.
//  Copyright © 2018年 马雨辰. All rights reserved.
//

#import "MYCExcelCell.h"

@interface MYCExcelCell()



@end

@implementation MYCExcelCell

-(void)setCellDic:(NSDictionary *)cellDic
{
    _cellDic = cellDic;
    _stringValueIndex = -1;
    [self refreshData];
    
}



-(void)refreshData
{
    NSDictionary *v = [self.cellDic objectForKey:@"v"];
    NSString *t = [self.cellDic objectForKey:@"t"];

    //解析下标
    //这个地方应该结合t的取值一起判断
    
    // t = @"s "，即为文本类型
    if([t isEqualToString:@"s"] && v && [v isKindOfClass:[NSDictionary class]]){
        self.stringValueIndex = [[v objectForKey:@"text"] integerValue];
    }
    
    NSString *r = [self.cellDic objectForKey:@"r"];
    
    NSString *rowStr = [MYCExcelCell getNumberFromStr:r];
    
    self.row = [rowStr integerValue];
    
    NSString *column = [MYCExcelCell getLetterFromStr:r];
    
    self.column = column;
}


-(void)setStringValue:(NSString *)stringValue
{
    _stringValue = stringValue;

}


/**
 获取字符串内数字
 */
+(NSString *)getNumberFromStr:(NSString *)str
{
    NSCharacterSet *nonDigitCharacterSet = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];
    return[[str componentsSeparatedByCharactersInSet:nonDigitCharacterSet] componentsJoinedByString:@""];
}



/**
 获取字符串内字母
 */
+(NSString *)getLetterFromStr:(NSString *)str
{
    NSString *numStr = [self getNumberFromStr:str];
    
    NSString *letterStr = [str substringWithRange:NSMakeRange(0, str.length - numStr.length)];
    
    return letterStr;
    
}


@end
